<?php

namespace app\common\entity;

use ReflectionClass;

abstract class Entity
{
    public function __toArray(): array
    {
        $reflection = new ReflectionClass($this);
        $properties = $reflection->getProperties();
        $res = [];
        foreach ($properties as $property) {
            if ($property->isStatic()) {
                continue;
            }
            $property->setAccessible(true);
            $value = $property->getValue($this);
            if (empty($value) && gettype($value)!=='integer') {
                continue;
            }
            $res[$property->getName()] = $value;
        }
        return $res;
    }
}